package com.aaa.controller.sas;

import com.aaa.entity.LayData;
import com.aaa.entity.MyPage;

import com.aaa.entity.User;
import com.aaa.entity.sas.TSasPlan;
import com.aaa.service.sas.TSasPlanService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * (TSasPlan)表控制层
 *
 * @author makejava
 * @since 2022-11-04 00:48:04
 */
@Controller
@RequestMapping("tSasPlan")
public class TSasPlanController {
    /**
     * 服务对象
     */
    @Autowired
    private TSasPlanService tSasPlanService;

    /*
        查询所有计划
     */
    @GetMapping("queryAll")
    @ResponseBody
    public LayData queryAll(MyPage page, TSasPlan tSasPlan){
        PageInfo pageInfo = tSasPlanService.queryAll(page,tSasPlan);
        return new LayData(pageInfo);
    }

    /*
        检查邀请码
     */
    @PostMapping("checkCode")
    @ResponseBody
    public LayData checkCode(TSasPlan tSasPlan){
        Boolean i = tSasPlanService.checkCode(tSasPlan);
        return new LayData(i);
    }

    /*
        检查计划名字是否存在
     */
    @PostMapping("{planname}")
    @ResponseBody
    public LayData checkPlanname(@PathVariable String planname){
        Boolean i = tSasPlanService.checkPlanname(planname);
        return new LayData(i);
    }

    /*
        添加/修改计划
     */
    @PostMapping("addOrUpdataPlan")
    @ResponseBody
    public LayData addOrUpdataPlan(TSasPlan tSasPlan, HttpSession session){
        User user = (User) session.getAttribute("user");
        Boolean i = tSasPlanService.addOrUpdataPlan(tSasPlan,user);
        return new LayData(i);
    }

    /*
        删除计划
     */
    @DeleteMapping("delPlan/{id}/{code}")
    @ResponseBody
    public LayData delPlan(@PathVariable Integer id,@PathVariable String code){
        System.out.println("code ======================== " + code);
        System.out.println("id ========================= " + id);
        Boolean i = tSasPlanService.delPlan(id,code);
        return new LayData(i);
    }

    /*
        修改状态
     */
    @PostMapping("updUserStatus")
    @ResponseBody
    public LayData updUserStatus(TSasPlan tSasPlan){
        Boolean i = tSasPlanService.updUserStatus(tSasPlan);
        return new LayData(i);
    }

    /*
        通过验证码获取数据
     */
    @GetMapping("getByCode")
    @ResponseBody
    public LayData getByCode(TSasPlan tSasPlan){
        TSasPlan tSasPlan1 = tSasPlanService.getByCode(tSasPlan);
        return new LayData(tSasPlan1);
    }

    /*
        通过邀请码获取计划的id
     */
    @PostMapping("getPlanId/{yqcode}")
    @ResponseBody
    public LayData getPlanId(@PathVariable String yqcode){
        int planId = tSasPlanService.getPlanId(yqcode);
        return new LayData(planId);
    }
}
